package com.lianxian.xindong.commonsdk.utils.filters;

import android.text.InputFilter;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @author EDZ
 */
public class FilterUtil {
    public static void addFilters(TextView textView, InputFilter inputFilter) {
        List<InputFilter> list = new ArrayList<>();
        list.add(inputFilter);
        addFilters(textView, list);
    }

    public static void addFilters(TextView textView, List<InputFilter> list) {
        if(textView == null) {
            return;
        }

        InputFilter[] filters = textView.getFilters();
        if(filters.length > 0) {
            Collections.addAll(list, filters);
        }
        InputFilter[] inputFilters = list.toArray(new InputFilter[0]);
        textView.setFilters(inputFilters);
    }
}
